import {
  add
} from "../../../api/machine";

const state = {
  curComponent: "detail1",
  choiceSysUpgradeType: "外设",
  list: [],
  selectedList: []
};

const mutations = {
  choice_SysUpgradeType(state, type) {
    state.choiceSysUpgradeType = type
  },
  list(state, list) {
    state.list = list;
  },
  add(state, obj) {
    state.selectedList.push(obj)
  },
  remove(state, obj) {
    state.selectedList = state.selectedList.filters(item => item.ID != obj.ID)
  }
};

const actions = {
  getList({
      commit
    },
    list
  ) {
    commit("list", list);
  },
  select({
    commit
  }, {
    obj,
    type
  }) { // type 1 选中 2 取消选中
    type == 1 ? commit("add", obj) : commit("remove", obj)
  }
};

const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};